/**
 * 
 */
package com.yidin.lsc;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.yidin.entry.MyDynamicEntry;
import com.yidin.entry.NearByStoreEntry;
import com.yidin.logic.MainService;
import com.yidin.logic.Task;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.ListView;
import android.widget.RadioGroup;
import android.widget.AdapterView.OnItemClickListener;

/**
 * 主导航之一附近商家
 * @author cola
 *
 */
public class NearByStore extends Container{
	protected Button listBtn;
	protected Button speedDialBtn;
	protected Button mapBtn;
	protected ViewGroup ViewContainer;
	protected Button rightBtn;
	protected ListView myListView;
	protected List<NearByStoreEntry> l = null;
	protected NearByStoreAdapter nearByStoreListAdapter;
	
	public NearByStore(Activity activity, View contentView, Views father) {
		super(activity, contentView, father);
		// TODO Auto-generated constructor stub
		this.initialize();
	}

	@Override
	public void checkCache() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void findView(View contentView) {
		// TODO Auto-generated method stub
		View view = null;
		view = inflater.inflate(R.layout.listview, null);

		ViewContainer.addView(view);

		this.listBtn = (Button) contentView.findViewById(R.id.list);
		this.listBtn.setText("列表");
		this.speedDialBtn = (Button) contentView.findViewById(R.id.speedDial);
		this.speedDialBtn.setVisibility(View.GONE);
		this.mapBtn = (Button) contentView.findViewById(R.id.map);
		this.mapBtn.setText("地图");
		this.rightBtn = (Button) contentView.findViewById(R.id.filter);
		myListView = (ListView) view
				.findViewById(R.id.myFriendListView);
	}

	@Override
	public void showFunctionsListView(View contentView) {
		// TODO Auto-generated method stub
		ViewContainer = (ViewGroup) contentView
				.findViewById(R.id.ViewContainer);
	}

	@Override
	public void initialize() {
		// TODO Auto-generated method stub
		if (l == null) {
			Map obj = new HashMap<String, String>();
			obj.put("AccountId", "hlf");
			obj.put("Area", "-1");
			obj.put("Classify", "-1");
			obj.put("JingDu", "100.000");
			obj.put("WeiDu", "80.000");
			obj.put("AccountTo", "hlf");
			obj.put("AccountFrom", "test");// testcompany
			((LscActivity) activity).showProgress(activity);//
			Task task = new Task(Task.TASK_NEARBY_SHIOLIST, obj);// TASK_ACCOUNT_DETAIL
			MainService.AddNewTask(task);// TASK_NEARBY_SHOPDETAIL
		} else
			myListView.setAdapter(nearByStoreListAdapter);
		
//		l = new ArrayList<NearByStoreEntry>();
//		NearByStoreEntry a = new NearByStoreEntry();
//		a.AccountId = "3232";
//		a.AccountName = "3232";
//		l.add(a);
//		nearByStoreListAdapter = new NearByStoreAdapter(l,activity);
//		myListView.setAdapter(nearByStoreListAdapter);
		
		this.myListView.setOnItemClickListener(listOnItemClickListener);
	}

	private OnItemClickListener listOnItemClickListener = new OnItemClickListener() {

		@Override
		public void onItemClick(AdapterView<?> parent, View view, int position,
				long id) {
			// TODO Auto-generated method stub
			Intent it = new Intent(activity, NearByStoreDetail.class);
			it.putExtra("AccountId", l.get(position).AccountId);//商家帐号
			activity.startActivity(it);
		}

	};
	
	@Override
	public void removeView() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void refresh(Object... param) {
		// TODO Auto-generated method stub
		int task = (Integer) param[0];
		switch (task) {
		case Task.TASK_NEARBY_SHIOLIST:
			l = (List<NearByStoreEntry>) param[1];
			if(l == null) return;
			nearByStoreListAdapter = new NearByStoreAdapter(l,activity);
			myListView.setAdapter(nearByStoreListAdapter);
			break;
		}
	}

}
